<template>
  <div id="other-login">
    <div class="other-login2">
      <div style="margin-left: 450px;margin-top: 30px">
        <p style="color:#9b9b9b">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QQ群：218851843</p>
        <img :src="imgUrl" width="200px">
        <p style="color:#9b9b9b">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;有疑问加群咨询</p>
      </div>
      <div style="margin-top: -300px">
        <h2>用户登录</h2>
        <el-form ref="form" :model="form" label-width="">
          <el-form-item>
            <el-input v-model="form.tel" style="width: 300px;" placeholder="电话号码" prefix-icon="el-icon-user"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="form.password" style="width: 300px" placeholder="密码" show-password
                      prefix-icon="el-icon-key"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit(form.tel,form.password)" style="width: 300px">登录</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-link type="info" style="margin-top: 50px;margin-left: 120px" :underline="false" @click="returnUrl()">返回>
      </el-link>
    </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "OtherLogin",
  data() {
    return {
      form: {
        tel: '',
        password: ''
      },
      imgUrl: require("@/assets/qrcode.jpg")
    }
  },
  methods: {
    onSubmit(tel, password) {
      if (tel == '') {
        this.$alert('电话未输入', '错误', {
          confirmButtonText: '确定',
        });
      } else if (password = '') {
        this.$alert('密码未输入', '错误', {
          confirmButtonText: '确定',
        });
      } else {
        axios('/open/login/tel', {
          params: {
            userTel: tel,
            userPassword: password,
          },
          method: 'post'
        }).then(res => {
          console.log(res.data)
          // console.log(res.data.data.school.schoolName)
          // console.log(res.data.data.userGender)
          let userInfo = {
            userId:res.data.data.userId,
            userName: res.data.data.userName,
            userGender: res.data.data.userGender,
            userTel: res.data.data.userTel,
            userPassword: res.data.data.userPassword,
            userEmail: res.data.data.userEmail,
            schoolName: res.data.data.school.schoolName,
            userHead:res.data.data.userHead,
            studentCollege:res.data.studentClass.studentCollege,
            studentClassGrade:res.data.studentClass.studentClassGrade,
            studentClassMajor:res.data.studentClass.studentClassMajor,
            studentClassNumber:res.data.studentClass.studentClassNumber,
            studentClassIndex:res.data.studentClass.studentClassIndex,
          }
          this.$store.commit('updateUser', userInfo)
          this.$store.commit('updateuserId',userInfo.userId)
          this.$router.push('/Home/Course')
        }).catch(function (error) {
          console.log(error);
        });
      }
    },
    returnUrl() {
      this.$router.push('/Login')
    }
  }
}
</script>

<style scoped>

#other-login {
  position: fixed;
  width: 100%;
  height: 100%;
  background: #e6e6e6;
}

.other-login2 {
  border-radius: 20px;
  margin-left: 23%;
  margin-top: 6%;
  padding: 80px;
  background: white;
  box-shadow: 4px 4px 4px #ccc;
  width: 700px;
  height: 360px;
}

</style>
